import { createStore } from '@/lib/createStore'

type State = {
  selectedCategoryId: number | null
  categoryDialogOpen: boolean
}

type Actions = {
  updateSelectedCategoryId: (id: number | null) => void
  updateCategoryDialogOpen: (isOpen: boolean) => void
}

type Store = State & Actions

const useCategoriesStore = createStore<Store>(
  set => ({
    selectedCategoryId: null,
    categoryDialogOpen: false,
    updateSelectedCategoryId: id => set(() => ({ selectedCategoryId: id })),
    updateCategoryDialogOpen: isOpen => set(() => ({ categoryDialogOpen: isOpen }))
  }),
  {
    skipPersist: true
  }
)

export { useCategoriesStore }
